using Microsoft.AspNetCore.Mvc;
using mvc8.Models;
using mvc8.Service1;
using System.Diagnostics;

namespace mvc8.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly IMyDependency _myDependency;

        public HomeController(ILogger<HomeController> logger,
            IMyDependency myDependency,IServiceProvider serviceProvider)
        {
            _logger = logger;
            _myDependency = myDependency;
            IMyDependency? myDependency1 = serviceProvider.GetService<IMyDependency>();
            myDependency1.WriteMessage("yejing");
        }

        public IActionResult Index()
        {
            _myDependency.WriteMessage("hello world");
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
